﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net.Config;
using log4net;

namespace Sync3DCartDatabase
{
    public class MessageWriter
    {
        private static bool isInitialized = false;

        public enum ISEnumLogLevel { DEBUG = 0, INFO = 1, WARN = 2, ERROR = 3, FATAL = 4 };
        public static void EventMessage(string msg, ISEnumLogLevel level, string logger)
        {
            
            if (!isInitialized)
                Initialize();

            ILog log;
            try
            {
                log = LogManager.GetLogger(logger);

                DateTime dt = DateTime.Now;
                switch (level)
                {

                    case ISEnumLogLevel.FATAL:
                        if (log.IsFatalEnabled) log.Fatal(msg);
                        break;
                    case ISEnumLogLevel.ERROR:
                        if (log.IsErrorEnabled) log.Error(msg);
                        break;
                    case ISEnumLogLevel.DEBUG:
                        if (log.IsDebugEnabled) log.Debug(msg);
                        break;
                    case ISEnumLogLevel.WARN:
                        if (log.IsWarnEnabled) log.Warn(msg);
                        break;
                    case ISEnumLogLevel.INFO:
                        if (log.IsInfoEnabled) log.Info(msg);
                        break;
                    default:
                        msg = "OFF";
                        break;
                }
            }
            catch (Exception ex)
            {
                //eventWriter.LogWindowsEvent("Error in logging message. Error: " + ex.ToString(), EventLogEntryType.Error);
            }
            finally
            {
                log = null;
            }
        }

        private static void Initialize()
        {
            XmlConfigurator.Configure();
            isInitialized = true;            
        }

    }
}
